gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns#139080
Open
cdce8p wants to merge 10 commits intopython:mainfrom
Open
gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns#139080cdce8p wants to merge 10 commits intopython:mainfrom
cdce8p wants to merge 10 commits intopython:mainfrom
Conversation
Contributor
|
@cdce8p Could you please resolve conflicts? |
Contributor
|
I believe this needs a what's new entry too. |
Contributor
Author
Maybe, but I think we should wait until both PRs are merged before adding a combined one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR complements and extends the work done in #138915.
In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword only patterns, the performance is much improved as it's no longer necessary to construct intermediary tuples so that's now only
~20%slower compared to theifequivalent. (Previously it was closer to~220%).Further improvements can likely be archived if
MATCH_CLASS_GET_OPT_ATTRis specialized in a similar manner toLOAD_ATTR. With the specialization for (just)LOAD_ATTRdisabled, thematchstatement equivalent is again slightly faster than the correspondingifclause.__
Micro benchmarks with all specializations enabled.
Micro benchmark (bare class pattern)
Micro benchmark (One keyword attribute)
📚 Documentation preview 📚: https://cpython-previews--139080.org.readthedocs.build/